// import { USER_KEY } from '@/constants'
// import MyLocalStorage from '@/utils/Mylocalstorage'
import { Button as AntButton, Popconfirm } from 'antd'
import { ReactNode } from 'react'

export interface ButtonProps extends React.ComponentProps<typeof AntButton> {
  /**
   * 设置按钮类名
   */
  className?: string
  /**
   * 设置按钮类型
   * @default default
   */
  type?: 'primary' | 'ghost' | 'dashed' | 'link' | 'text' | 'default'
  /**
   * 设置危险按钮
   * @default false
   */
  danger?: boolean
  /**
   * 设置按钮的图标组件
   */
  icon?: React.ReactNode
  /**
   * 设置按钮失效状态
   * @default false
   */
  disabled?: boolean
  /**
   * 幽灵属性，使按钮背景透明
   * @default false
   */
  ghost?: boolean
  /**
   * 设置按钮载入状态
   * @default false
   */
  loading?: boolean | { delay: number }
  /**
   * 设置按钮大小
   * @default middle
   */
  size?: 'large' | 'middle' | 'small'
  /**
   * 设置按钮权限
   * @default undefined
   */
  permission?: number[]
}

export const Button = ({ permission, children, ...restProps }: ButtonProps) => {
  // if (permission && !permission.includes(MyLocalStorage.localstorage.getItem<UserInfo>(USER_KEY)?.permission)) {
  //   return null
  // }
  return <AntButton {...restProps}>{children}</AntButton>
}

interface ConfirmBtnProps {
  title?: ReactNode
  children: ReactNode
  onClick: FcProps
  disabled?: boolean
}

export const ConfirmBtn = ({ title = '确定删除吗?', children, onClick, disabled }: ConfirmBtnProps) => {
  return (
    <Popconfirm
      title={title}
      onConfirm={e => {
        !disabled && onClick?.(e)
      }}
      disabled={disabled}
      placement={'topRight'}
    >
      <Button disabled={disabled}>{children}</Button>
    </Popconfirm>
  )
}

export const ConfirmLinkBtn = ({ title = '确定删除吗?', children, onClick, disabled }: ConfirmBtnProps) => {
  return (
    <Popconfirm
      title={title}
      onConfirm={e => {
        !disabled && onClick?.(e)
      }}
      disabled={disabled}
      placement={'topRight'}
    >
      <Button disabled={disabled} type="primary" ghost>
        {children}
      </Button>
    </Popconfirm>
  )
}
